/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tk.eigh.ksvg.types;

import tk.eigh.ksvg.SVGException;

/**
 *
 * @author nt
 */
public class SVGNumber {

    protected final static String NUMBER_PATTERN_STRING =
            "[+-]?\\s*\\d+\\s*(?:[Ee]\\s*\\d+)?|[+-]?\\s*\\d*\\.\\d+\\s*(?:[Ee]\\s*\\d+)?";
    private float _value;

    public SVGNumber(float value) {
        this._value = value;
    }

    public SVGNumber(String text) {
        try {
            this._value = SVGInteger.parseText(text);
        } catch (SVGException ex1) {
            try {
                this._value = Float.parseFloat(text);
            } catch (NumberFormatException ex2) {
                if (!text.equals("inherit")) {
                    throw new SVGException(ex2);
                }
            }
        }
    }

    public Float getValue() {
        return Float.valueOf(_value);
    }

    @Override
    public String toString() {
        return String.format("%2.4f",_value);
    }
}
